// Author: Tang Qiao
// Date:   2012-3-2
//
// The macro is inspired from:
//     http://www.yifeiyang.net/iphone-development-skills-of-the-debugging-chapter-2-save-the-log/

#ifdef DEBUG
#define debugLog(...) NSLog(__VA_ARGS__)
#define debugMethod() NSLog(@"%s", __func__)
#else
#define debugLog(...)
#define debugMethod()
#endif

#ifndef DEBUG
#define NSLog(...)
#endif

//国际化
#define LocalizedString(key) \
[[InternationalControl bundle] localizedStringForKey:(key) value:nil table:@"Localizable"]

#define STR(key)            NSLocalizedString(key, nil)

//文件路径
#define PATH_OF_APP_HOME    NSHomeDirectory()
#define PATH_OF_TEMP        NSTemporaryDirectory()
#define PATH_OF_DOCUMENT    [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

//
#define ScreenScale  ([[UIScreen mainScreen] scale])
#define IsLandscape   (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))

//iphone尺寸
#define ScreenWidth    ((IOS8 || !IsLandscape) ?[UIScreen mainScreen].bounds.size.width:[UIScreen mainScreen].bounds.size.height)
#define ScreenHeight   ((IOS8 || !IsLandscape) ?[UIScreen mainScreen].bounds.size.height:[UIScreen mainScreen].bounds.size.width)

//设置颜色更方便
#define color_with_rgba(r,g,b,a) [[UIColor alloc] initWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
#define color_with_rgb(r,g,b) [[UIColor alloc] initWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define systemBlueColor color_with_rgb(0, 105, 255)

//ios系统
//系统版本枚举除了iOS5外,都是指大于等于当前那个版本,如IOS6表示当前版本号大于等于6.0
//所以在这个基础上，如果要判断当前版本是6.0版本就必须是: (IOS6 && !IOS7)
//但是不推荐这样的做法,大部分的系统判断都可以用responseToSelector替代
//只有在少部分大量用到某个版本以上API的地方才使用
#define IOS9            ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 9.0)
#define IOS8            ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0)
#define IOS8_2          ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.2)
#define IOS7            ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7.0)
#define IOS7_1          ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7.1)

//16进制颜色转换
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0x00FF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0x0000FF))/255.0 \
alpha:1.0]

#define UIColorFromRGBA(rgbValue, alphaValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0x00FF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0x0000FF))/255.0 \
alpha:alphaValue]

//简单弹窗显示
#define SHOW_ALERT(title,msg,cancelTitle) [[[UIAlertView alloc] initWithTitle:(title) \
message:(msg) \
delegate:nil \
cancelButtonTitle:(cancelTitle) \
otherButtonTitles:nil] show]

// 游戏比例（暂时不考虑iphone4）
#define ScreenGameScale (ScreenHeight/375.)

typedef void (^MSCompletionBlock)(void);
